import Vue from 'vue'
import VueRouter from 'vue-router'

import store from './store'

import WrapApp from 'components/WrapApp'
import WrapSys from 'components/WrapSys'

import Err from 'components/Err'
import Login from 'components/Login'

import Home from 'components/Home'
import newHome from 'components/Home/Home'
import newmore from 'components/Home/newmore'
import result from 'components/Home/result'


import Info from 'components/Info'
import Topic from 'components/Topic'
import Report from 'components/Report'
import Setting from 'components/Setting'

import Details from 'components/Info/details'
import pressList from 'components/Info/pressList'

// 专题
import skip from 'components/Topic/skip'
import eventTraces from 'components/Topic/eventTraces'
import evens from 'components/Topic/evens'
import media from 'components/Topic/media'
import chart from 'components/Topic/chart'
import topicUpdate from 'components/Topic/topicUpdate'
import addTopic from 'components/Topic/addTopic'

// setting
import manage from 'components/Setting/manage'
import monitor from 'components/Setting/monitor'
import Blacklist from 'components/Setting/Blacklist'
import filterkey from 'components/Setting/filterkey'

// personal
import personal from 'components/personal/index'
import modifyinfo from 'components/personal/ModifyInfo'
import mycollection from 'components/personal/MyCollection'
import warningsetting from 'components/personal/WarningSetting'
import loginlog from 'components/personal/LoginLog'
import wSetting from 'components/personal/wSetting'

// others
import Help from 'components/feedback/help'
import feedback from 'components/feedback/feedback'
import error from 'components/feedback/error'

// 简报
import brief from 'components/brief'
import briefprocess from 'components/brief/briefprocess'
import confirmsc from 'components/brief/confirmsc'
import choosestyle from 'components/brief/choosestyle'
import step01 from 'components/brief/step-01'
import publicopinionlist from 'components/brief/publicopinionlist'
import textsearch from 'components/brief/textsearch'
import briefsuccess from 'components/brief/briefsuccess'
import editbrief from 'components/brief/editbrief'

// 新手指引
import guide from 'components/guide'

import report from 'components/officework/report'
import approval from 'components/officework/approval'

// 定向

import directional from 'components/directional'




Vue.use(VueRouter)

var router = new VueRouter({
  routes: [{
    path: '/',
    redirect: '/login'
  },{
    path: '/',
    component: WrapApp,
    children: [{
      path: '/home',
      component: Home,
      children:[
        {path:'',redirect:'page'},
        {path:'page',component:newHome},
        {path:'page/:id',component:newmore},
      ]
    },{
      path: '/error',
      component: error
    },{
      path: '/info',
      component: Info
    },{
      path: '/guide',
      component: guide
    },{
      path: '/Help',
      component: Help
    },{
      path: '/feedback',
      component: feedback
    },{
      path: '/report',
      component: report
    },{
      path: '/approval',
      component: approval
    },{
      path: '/directional',
      component: directional
    },{
      path: '/topic',
      component: skip,
      children:[
        {path:'',redirect:'list'},
        {path:'list',component:Topic},
        {path:'addTopic',component:addTopic},
        {path:'eventTraces',component:eventTraces,
          children:[
          {path:'evens',component:evens},
          {path:'media',component:media},
          {path:'chart',component:chart},
          {path:'topicUpdate',component:topicUpdate}
          ]
        }
        ]
    },{
      path: '/report',
      component: Report
    },{
      path: '/setting',
      component: Setting,
      children:[
        {path:'',redirect:'manage'},
        {path:'manage',component:manage},
        {path:'monitor',component:monitor},
        {path:'Blacklist',component:Blacklist},
        {path:'filterkey',component:filterkey}
        ]
    },{
      path: '/brief',
      component: brief,
      children:[
        {path:'',redirect:'briefprocess/tem'},
        {path:'briefprocess/:id',component:briefprocess},
        {path:'confirmsc',component:confirmsc},,
        {path:'step01',component:step01},
        {path:'choosestyle',component:choosestyle},
        {path:'list',component:publicopinionlist},
        {path:'textsearch',component:textsearch},
        {path:'briefsuccess',component:briefsuccess},
        {path:'editbrief/:id',component:editbrief}
        ]
    },{
      path: '/setting',
      component: Setting,
    },{
      path: '/details',
      component: Details
    },{
      path: '/result',
      component: result
    },{
      path: '/personal',
      component: personal,
      children:[
        {path:'modifyinfo',component:modifyinfo},
        {path:'mycollection',component:mycollection},
        {path:'warningsetting',component:warningsetting},
        {path:'loginlog',component:loginlog},
        {path:'warningsetting/wSetting',component:wSetting}
      ]
    }]
  },{
    path: '/',
    component: WrapSys,
    children: [{
      path: '/login',
      component: Login
    },{
      path: '/*',
      redirect: '/error'
    }]
  }]
})

// router.beforeEach((to, from, next) => {
//   var topath0 = to.path.split('/')[1]
//   var isLogin = store.state.User.login
//   var token = store.state.User.token
//   console.log(topath0)
//   console.log(token)
//     if(isLogin){
//         if(['loading', 'login'].indexOf(topath0) >= 0){
//             next('/home')
//           }else{
//             next()
//           }
//     }else{
//         if(token){
//           if(topath0=='details'){
//             next()
//           }else if(topath0 == 'loading'){
//             next()
//           }else{
//             next('/loading')
//           }
//         }else{
//           topath0 == 'login' ? next() : next('/login')
//         }
//     }
// })
//  router.beforeEach((to, from, next) => {
//    var topath0 = to.path.split('/')[1]
//    var  token = store.state.User.token
//    console.log([to,from ,token] )
//    if(topath0=='login'){
//      next()
//    }else{
//       if(token){
//         next()
//         console.log('实时1')
//       }else{
//         next('/login')
//       }
//    }
  
//  })

export default router
